import router from '@system.router';
import app from '@system.app';
var cmdno = {init:0,close:1,read:2,dian:3,deng:4}
export default {
    data: {
        title: '智能风扇',
        mydata: {
            Temp: 0,
            Hum: 0,
            Lux: 0,
            Motor: 'OFF',
            LED: 'OFF'
        },
        interval:0
    },
    //数据初始化设置
    onInit(){
        app.e53ia1service({
            cmd:cmdno.init,
            success(res){
            },
            fail(res){
            },
            complete(res){

            },
        })
        this.interval = setInterval(()=>this.queryData(),2000)
    },
    //灯指令控制
    dengChange(){
        let that = this
        let flag = ''
        if(this.mydata.LED == 'OFF'){
            flag = 'ON'
        }
        else{
            flag = 'OFF'
        }
        app.e53ia1service({
            cmd:cmdno.deng,
            data:flag,
            success(res){
                that.mydata = JSON.parse(res.e53_ia1)
            },
            fail(res){

            },
            complete(res){

            },
        })
    },
    //风扇指令控制
    dianChange(){
        let that = this
        let flag = ''
        if(this.mydata.Motor == 'OFF'){
            flag = 'ON'
        }
        else{
            flag = 'OFF'
        }
        app.e53ia1service({
            cmd:cmdno.dian,
            data:flag,
            success(res){
                that.mydata = JSON.parse(res.e53_ia1)
            },
            fail(res){

            },
            complete(res){

            },
        })
    },
    queryData(){
        let that = this
        app.e53ia1service({
            cmd:cmdno.read,
            data:'',
            success(res){
                that.mydata = JSON.parse(res.e53_ia1)
            },
            fail(res){

            },
            complete(res){

            },
        })
    },
    //退出
    exit(){
        app.terminate()
    },
    route(e){
        router.replace({
            uri: e.uri
        });
    }
}
